from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-15 14:02:39.078014
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 15, Nov, 2022
Time: 14:02:46
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9528
Nobs: 841.000 HQIC: -51.2653
Log likelihood: 10988.8 FPE: 4.48176e-23
AIC: -51.4595 Det(Omega_mle): 4.02946e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298675 0.050641 5.898 0.000
L1.Burgenland 0.109869 0.034797 3.157 0.002
L1.Kärnten -0.105992 0.018539 -5.717 0.000
L1.Niederösterreich 0.211221 0.072787 2.902 0.004
L1.Oberösterreich 0.100927 0.069223 1.458 0.145
L1.Salzburg 0.251878 0.036910 6.824 0.000
L1.Steiermark 0.037088 0.048396 0.766 0.443
L1.Tirol 0.107247 0.039224 2.734 0.006
L1.Vorarlberg -0.060140 0.033821 -1.778 0.075
L1.Wien 0.053366 0.061953 0.861 0.389
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067407 0.104449 0.645 0.519
L1.Burgenland -0.030362 0.071772 -0.423 0.672
L1.Kärnten 0.047617 0.038237 1.245 0.213
L1.Niederösterreich -0.173605 0.150129 -1.156 0.248
L1.Oberösterreich 0.379213 0.142776 2.656 0.008
L1.Salzburg 0.288324 0.076129 3.787 0.000
L1.Steiermark 0.107690 0.099821 1.079 0.281
L1.Tirol 0.315762 0.080902 3.903 0.000
L1.Vorarlberg 0.023085 0.069757 0.331 0.741
L1.Wien -0.018774 0.127782 -0.147 0.883
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197127 0.026218 7.519 0.000
L1.Burgenland 0.092543 0.018016 5.137 0.000
L1.Kärnten -0.008673 0.009598 -0.904 0.366
L1.Niederösterreich 0.268203 0.037684 7.117 0.000
L1.Oberösterreich 0.115213 0.035839 3.215 0.001
L1.Salzburg 0.052563 0.019109 2.751 0.006
L1.Steiermark 0.016471 0.025056 0.657 0.511
L1.Tirol 0.098257 0.020307 4.838 0.000
L1.Vorarlberg 0.056250 0.017510 3.212 0.001
L1.Wien 0.113060 0.032075 3.525 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105196 0.026863 3.916 0.000
L1.Burgenland 0.047178 0.018459 2.556 0.011
L1.Kärnten -0.017166 0.009834 -1.746 0.081
L1.Niederösterreich 0.197286 0.038611 5.110 0.000
L1.Oberösterreich 0.280160 0.036720 7.630 0.000
L1.Salzburg 0.120778 0.019579 6.169 0.000
L1.Steiermark 0.101538 0.025673 3.955 0.000
L1.Tirol 0.123193 0.020807 5.921 0.000
L1.Vorarlberg 0.069087 0.017941 3.851 0.000
L1.Wien -0.028038 0.032864 -0.853 0.394
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129972 0.048675 2.670 0.008
L1.Burgenland -0.049455 0.033447 -1.479 0.139
L1.Kärnten -0.039553 0.017819 -2.220 0.026
L1.Niederösterreich 0.166330 0.069962 2.377 0.017
L1.Oberösterreich 0.139111 0.066536 2.091 0.037
L1.Salzburg 0.285145 0.035477 8.037 0.000
L1.Steiermark 0.032847 0.046518 0.706 0.480
L1.Tirol 0.163327 0.037701 4.332 0.000
L1.Vorarlberg 0.104044 0.032508 3.201 0.001
L1.Wien 0.069948 0.059548 1.175 0.240
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058939 0.038552 1.529 0.126
L1.Burgenland 0.042655 0.026491 1.610 0.107
L1.Kärnten 0.049836 0.014113 3.531 0.000
L1.Niederösterreich 0.228201 0.055413 4.118 0.000
L1.Oberösterreich 0.272456 0.052699 5.170 0.000
L1.Salzburg 0.058352 0.028099 2.077 0.038
L1.Steiermark -0.006963 0.036844 -0.189 0.850
L1.Tirol 0.156203 0.029861 5.231 0.000
L1.Vorarlberg 0.067854 0.025747 2.635 0.008
L1.Wien 0.072966 0.047165 1.547 0.122
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184671 0.046148 4.002 0.000
L1.Burgenland -0.004499 0.031710 -0.142 0.887
L1.Kärnten -0.060909 0.016894 -3.605 0.000
L1.Niederösterreich -0.086239 0.066330 -1.300 0.194
L1.Oberösterreich 0.192383 0.063081 3.050 0.002
L1.Salzburg 0.059659 0.033635 1.774 0.076
L1.Steiermark 0.225721 0.044103 5.118 0.000
L1.Tirol 0.494716 0.035744 13.841 0.000
L1.Vorarlberg 0.047546 0.030820 1.543 0.123
L1.Wien -0.051071 0.056457 -0.905 0.366
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158714 0.052550 3.020 0.003
L1.Burgenland -0.009342 0.036110 -0.259 0.796
L1.Kärnten 0.064830 0.019238 3.370 0.001
L1.Niederösterreich 0.203756 0.075532 2.698 0.007
L1.Oberösterreich -0.067768 0.071833 -0.943 0.345
L1.Salzburg 0.223380 0.038302 5.832 0.000
L1.Steiermark 0.113345 0.050221 2.257 0.024
L1.Tirol 0.084089 0.040703 2.066 0.039
L1.Vorarlberg 0.122097 0.035096 3.479 0.001
L1.Wien 0.108501 0.064290 1.688 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357093 0.030927 11.546 0.000
L1.Burgenland 0.008720 0.021251 0.410 0.682
L1.Kärnten -0.024546 0.011322 -2.168 0.030
L1.Niederösterreich 0.229724 0.044453 5.168 0.000
L1.Oberösterreich 0.158700 0.042276 3.754 0.000
L1.Salzburg 0.054130 0.022541 2.401 0.016
L1.Steiermark -0.018524 0.029557 -0.627 0.531
L1.Tirol 0.116924 0.023955 4.881 0.000
L1.Vorarlberg 0.071556 0.020655 3.464 0.001
L1.Wien 0.047373 0.037836 1.252 0.211
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043686 0.161081 0.192525 0.166006 0.131791 0.124184 0.070036 0.230554
Kärnten 0.043686 1.000000 0.001714 0.131749 0.045163 0.099469 0.427941 -0.050749 0.102144
Niederösterreich 0.161081 0.001714 1.000000 0.345789 0.166767 0.311529 0.127783 0.192233 0.341094
Oberösterreich 0.192525 0.131749 0.345789 1.000000 0.236045 0.341093 0.178223 0.180144 0.275279
Salzburg 0.166006 0.045163 0.166767 0.236045 1.000000 0.153403 0.145334 0.152964 0.141308
Steiermark 0.131791 0.099469 0.311529 0.341093 0.153403 1.000000 0.163397 0.148861 0.092666
Tirol 0.124184 0.427941 0.127783 0.178223 0.145334 0.163397 1.000000 0.121830 0.163956
Vorarlberg 0.070036 -0.050749 0.192233 0.180144 0.152964 0.148861 0.121830 1.000000 0.018036
Wien 0.230554 0.102144 0.341094 0.275279 0.141308 0.092666 0.163956 0.018036 1.000000